package com.zjw.zy.coreui.dialog;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.zjw.zy.smi.JustWithIt;
import com.zjw.zy.utils.AppUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class OneListDialog<VALUE> extends BaseListDialog<VALUE, VALUE, VALUE> {

    public static <VALUE> OneListDialog<VALUE> get(@NonNull Map<String, VALUE> data) {
        OneListDialog<VALUE> listDialog = new OneListDialog<>(AppUtils.getMainActivity());
        List<String> keys = new ArrayList<>();
        List<VALUE> values = new ArrayList<>();
        for (Map.Entry<String, VALUE> entry : data.entrySet()) {
            keys.add(entry.getKey());
            values.add(entry.getValue());
        }
        listDialog.bindData(keys, values);
        return listDialog;
    }


    protected OneListDialog(@NonNull Context context) {
        super(context);
    }

    protected OneListDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected OneListDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    public void bindData(@NonNull List<String> keys, @NonNull List<VALUE> values) {
        super.bindData(keys, values);
    }


    public OneListDialog<VALUE> selectValue(VALUE value) {
        select1Value(value);
        return this;
    }

    @Override
    public OneListDialog<VALUE> title(@NonNull String title) {
        super.title(title);
        return this;
    }

    public OneListDialog<VALUE> bindNegativeCallback(JustWithIt<VALUE> call) {
        BaseListDialog<VALUE, VALUE, VALUE> callback = super.bindNegativeCallback((obj1, obj2, obj3) -> call.onWith(obj1));
        return this;
    }

    public OneListDialog<VALUE> bindPositiveCallback(JustWithIt<VALUE> call) {
        BaseListDialog<VALUE, VALUE, VALUE> callback = super.bindPositiveCallback((obj1, obj2, obj3) -> call.onWith(obj1));
        return this;
    }
}
